package evolution.operation.migration;

import java.util.List;

import evolution.algorithm.CoevolutionAlgorithm;
import evolution.executor.EvolutionaryAlghorithmEpochRunner;
import evolution.individual.Individual;

public class OneSidedCircleMigration extends AbstractMigrationStrategy {

	@Override
	public void migrate(CoevolutionAlgorithm coevolutionAlghoritm) {
		List<EvolutionaryAlghorithmEpochRunner> evolutionaryAlghorithmEpochRunners = coevolutionAlghoritm
				.getEvolutionaryAlghorithmEpochRunners();
		Individual[][] populations = MigrationHelper
				.extractPopulations(evolutionaryAlghorithmEpochRunners);
		Individual[][] bestLists = MigrationHelper.buildBestIndividualsLists(
				populations, migrationSize);

		int length = bestLists.length;
		for (int i = 0; i < length; i++) {
			Individual[] best = bestLists[i];
			Individual[] populationNext = populations[(i + 1) % length];

			MigrationHelper.replaceLastN(best, populationNext, migrationSize);
		}
	}
}
